package com.mo.ld

import android.os.*
import androidx.fragment.app.Fragment
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.dylanc.longan.pressBackTwiceToExitApp
import com.dylanc.longan.sp
import com.dylanc.longan.topActivity
import com.mo.ld.activity.animation.*
import com.mo.ld.activity.cust.CustsActivity
import com.mo.ld.activity.gate.GateListActivity
import com.mo.ld.activity.interactive.*
import com.mo.ld.activity.view.*
import com.mo.ld.bean.ActionBean
import com.mo.ld.modle.getMainAdapter2
import com.mo.lib.ui.activity.BaseVpActivity
import com.mo.lib.ui.fragment.BaseRvFragment
import com.mo.lib.utils.KLog
import com.mo.lib.utils.startActivity
import com.mo.lib.view.recyclerview.layoutG

/**
 * @ author：mo
 * @ data：2022/3/25:14:57
 * @ 功能：
 */

class MainActivity : BaseVpActivity() {
    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        KLog.i("       initView      ")
        pressBackTwiceToExitApp("再按一次退出应用程序")
    }

    override val vpTitleList: ArrayList<String>
        get() = object : ArrayList<String>() {
            init {
                add("控件")
                add("交互")
                add("动画")
            }
        }
    override val vpFragmentsList: ArrayList<Fragment>
        get() = object : ArrayList<Fragment>() {
            init {
                add(FragmentWidget())
                add(FragmentInteractive())
                add(FragmentAnimation())

            }
        }

    override fun initData() {
        super.initData()
    }

    override fun onBackPressed() { //        super.onBackPressed()
        if (viewBinding.stlBaserVp.currentTab != 0) {
            viewBinding.vpBaserVp.currentItem -= 1
        } else {
            super.onBackPressed()
        }
topActivity
    }
}

class FragmentWidget : BaseRvFragment<ActionBean>() {
    private fun getData(): MutableList<ActionBean> {
        return mutableListOf(
            ActionBean("View"){
               startActivity<ViewsActivity>()
            },
            ActionBean("RecyclerView"){
                startActivity<RecyclerViewActivity>()
            },
            ActionBean("SpannableStringBuilder"){
                startActivity<SpannableStringBuilderActivity>()
            },
            ActionBean("TextView"){
                startActivity<TextViewsVbActivity>()
            },
            ActionBean("ProgressView"){
                startActivity<ProgressViewsActivity>()
            },
            ActionBean("EditText"){
                startActivity<EditTextViewsActivity>()
            },
            ActionBean("流式布局"){
                startActivity<FlowLayoutActivity>()
            },
            ActionBean("GATE"){
                startActivity<GateListActivity>()
            },
            ActionBean("广播"){
                startActivity<BroadcastReceiverActivity>()
            },
            ActionBean("联动Behavior"){
                startActivity<BehaviorActivity>()
            },
            ActionBean("图表"){
                startActivity<AndroidchartActivty>()
            },
            ActionBean("城市选择"){
                startActivity<CitySelectActivity>()
            },
        )
    }

    override fun getList(page: Int) {}
    override fun getMore(page: Int) {}

    override fun initView(arguments: Bundle?) {
        super.initView(arguments)
        viewBinding.krvBaseList.layoutG(3)
        loadList(getData())
        topActivity
    }

    override fun creatAdaper(): BaseQuickAdapter<ActionBean, BaseViewHolder> {
        return getMainAdapter2( mutableListOf())
    }
}

class FragmentInteractive : BaseRvFragment<ActionBean>() {

    private fun getData(): MutableList<ActionBean> {
        return mutableListOf(
            ActionBean("跳转"){
                startActivity<BengsActivity>()
            },
            ActionBean("Dialog"){
                startActivity<DialogsActivity>()
            },
            ActionBean("Popwindow"){
                startActivity<PopwindowActivity>()
            },
            ActionBean("状态栏"){
                startActivity<StatusBarActivity>()
            },
            ActionBean("拍照"){
                startActivity<CamraActivity>()
            },
            ActionBean("AOP"){
                startActivity<AopActivity>()
            },
            ActionBean("定位"){
                startActivity<LoctionActivity>()
            },
            ActionBean("键盘"){
                startActivity<KeybordActivity>()
            },
            ActionBean("地图"){
                startActivity<MapActivity>()
            },
            ActionBean("多进程通信"){
                startActivity<ProscessesActivityOne>()
            },
            ActionBean("协程"){
                startActivity<CoroutinesActivity>()
            },
            ActionBean("DataBinding"){
                startActivity<DataBindingActivity>()
            },
            ActionBean("时间相关"){
                startActivity<TimeAboutActivity>()
            },
            ActionBean("ViewModel"){
                startActivity<ViewModelActivity>()
            },
            ActionBean("自定义需求"){
                startActivity<CustsActivity>()
            },

        )
    }

    override fun getList(page: Int) {}
    override fun getMore(page: Int) {}

    override fun initView(arguments: Bundle?) {
        super.initView(arguments)
        viewBinding.krvBaseList.layoutG(3)
    }

    override fun creatAdaper(): BaseQuickAdapter<ActionBean, BaseViewHolder> {
        return getMainAdapter2(getData())
    }
}

class FragmentAnimation : BaseRvFragment<ActionBean>() {

    private fun getData(): MutableList<ActionBean> {
        return mutableListOf(
            ActionBean("ObjectAnimator"){
                startActivity<ObjectAnimatorActivity>()
            },
            ActionBean("lottie"){
                startActivity<LottieActivity>()
            },
            ActionBean("红旗"){
                startActivity<RedFlagActivity>()
            },
            ActionBean("波浪"){
                startActivity<WaveViewsActivity>()
            },
            ActionBean("AsynAnimUtil"){
                startActivity<AsynAnimUtilVbActivity>()
            },
            ActionBean("塔罗牌"){
                startActivity<PokerActivity>()
            },
            ActionBean("简单动效"){
                startActivity<AnimationsActivity>()
            },

        )
    }

    override fun initView(arguments: Bundle?) {
        super.initView(arguments)
        viewBinding.krvBaseList.layoutG(3)
    }

    override fun getList(page: Int) {}
    override fun getMore(page: Int) {}

    override fun creatAdaper(): BaseQuickAdapter<ActionBean, BaseViewHolder> {
        return getMainAdapter2( getData())
    }
}
